package com.story.aistory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.story.aistory.domain.po.LikeRecord;
import com.story.aistory.mapper.LikeRecordMapper;
import com.story.aistory.service.ILikeRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hui
 * @since 2025-03-12
 */
@Service
public class LikeRecordServiceImpl extends ServiceImpl<LikeRecordMapper, LikeRecord> implements ILikeRecordService {

    @Override
    public void saveLikeRecord(Integer id, Integer storyId) {
        LikeRecord likeRecord = new LikeRecord();
        likeRecord.setStoryId(storyId);
        likeRecord.setUserId(id);
        this.save(likeRecord);
    }

    @Override
    public void deleteLikeRecord(Integer id, Integer storyId) {
        this.remove(new QueryWrapper<LikeRecord>().eq("user_id", id).eq("story_id", storyId));
    }

    @Override
    public boolean isLike(Integer userId, Integer storyId) {
        QueryWrapper<LikeRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId).eq("story_id", storyId);
        return this.count(queryWrapper) > 0;
    }
}
